import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'

//处理编程式导航的双击问题
const originPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, resolve, reject){
    if(resolve && reject){
        return originPush.call(this,location, resolve, reject)
    }else{
        return originPush.call(this,location).catch(()=>{})
    }
}

export default new VueRouter({
    routes:[
        {
            path:"/home",
            component:Home
        },
        {
            path:"/search/:keyword?",
            component:Search,
            name:"search",
            props:(route)=>{
                return {
                    keyword:route.params.keyword,
                    keyword1:route.query.keyword1,
                    username:"lisi"
                }
            }
        },
        {
            path:"/login",
            component:Login,
            meta:{
                isHidden:true
            }
        },
        {
            path:"/register",
            component:Register,
            meta:{
                isHidden:true
            }
        },
        {
            path:"/",
            redirect:"/home",
           
        }
    ]
})